/*
 * desktop.cpp
 *
 *  Created on: 2021年3月23日
 *      Author: root
 */
#include <gui/desktop.h>

using namespace myos;
using namespace myos::common;
using namespace myos::gui;

Desktop::Desktop(int32_t w,int32_t h,uint8_t r,uint8_t g,uint8_t b)
:CompositeWidget(0,0,0,w,h,r,g,b),
 MouseEventHandle()
{
	MousX=w/2;
	MousY=h/2;
}

Desktop::~Desktop(){

}

void Desktop::Draw(GraphicsContext* gc){
	CompositeWidget::Draw(gc);

	for(int i=0;i<4;i++){
		//
		gc->PutPixel(MousX-i, MousY, 0XFF, 0XFF, 0XFF);
		gc->PutPixel(MousX+i, MousY, 0XFF, 0XFF, 0XFF);
		gc->PutPixel(MousX, MousY-i, 0XFF, 0XFF, 0XFF);
		gc->PutPixel(MousX, MousY+i, 0XFF, 0XFF, 0XFF);
	}

}

void Desktop::OnMouseDown(uint8_t button ){
	CompositeWidget::OnMouseDown(MousX, MousY, button);
}

void Desktop::OnMouseUP(uint8_t button ){
	CompositeWidget::OnMouseUP(MousX, MousY, button);
}

void Desktop::OnMouseMove(int x,int y){

	x/=4;
	y/=4;
	int32_t newMousX=MousX+x;
	if(newMousX<0) newMousX=0;
	if(newMousX>=w) newMousX=w-1;

	int32_t newMousY=MousY+y;
	if(newMousY<0) newMousY=0;
	if(newMousY>=h) newMousY=h-1;

	CompositeWidget::OnMouseMove(MousX, MousY, newMousX, newMousY);
	MousX=newMousX;
	MousY=newMousY;
}



